package com.example.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.shop.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper extends BaseMapper<User> {


    @Insert("insert into user(user_id,user_avatar,user_name,user_sex,user_area," +
            "user_date_birth,user_account,user_password,user_face_token," +
            "user_phone,user_email,user_signature,user_state," +
            "user_resource_dir,user_register_date) " +
            "values(#{et.userId},#{et.userAvatar},#{et.userName},#{et.userSex},#{et.userArea}," +
            "#{et.userDateBirth},#{et.userAccount},#{et.userPassword},#{et.userFaceToken}," +
            "#{et.userPhone},#{et.userEmail},#{et.userSignature},${et.userState}," +
            "#{et.userResourceDir},#{et.userRegisterDate})")
    int insert(@Param(Constants.ENTITY) User user);

    @Update("update user set ${dbFiled} = #{value} where user_id = ${id}")
    int updateFieldById(@Param("id") long id,@Param("dbFiled") String dbFiled,@Param("value") String value);


    @Delete("DELETE `user`, evaluation, r_evaluation_comments, r_evaluation_comments_reply, r_evaluation_user_thumb_up " +
            "from " +
            "`user` " +
            "left join evaluation " +
            "on `user`.user_id = evaluation.user_id " +
            "left join r_evaluation_comments " +
            "on `user`.user_id = r_evaluation_comments.comments_user_id " +
            "left join r_evaluation_comments_reply " +
            "on (`user`.user_id = r_evaluation_comments_reply.comments_user_id or `user`.user_id = r_evaluation_comments_reply.reply_comments_user_id) " +
            "left join r_evaluation_user_thumb_up " +
            "on `user`.user_id = r_evaluation_user_thumb_up.user_id " +
            "where `user`.user_id = ${id}")
    int deleteAllInfoAboutUser(@Param("id")long id);

}
